/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui.tbl;

import java.awt.Component;
import java.util.EventObject;
import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import org.apache.log4j.Logger;

/**
 * This class is used for both Editor and Renderer
 * @author tnmkhoi
 */
public abstract class ImgBaseCell<E extends Component, R extends Component> extends AbstractCellEditor implements TableCellEditor, TableCellRenderer {
  private final Logger log = Logger.getLogger(this.getClass());
//  private JTable table;
//  private int clickedRow;
//  private int clickedCol;
  private Object cellValue;
  protected E editorComp;
  protected R rendererComp;

  public ImgBaseCell() {
  }
  
  @Override
  public Object getCellEditorValue() {
//    log.trace("getCellEditorValue [" + clickedRow + ", " + clickedCol + "], value: "+cellValue);
    return cellValue;
  }

  @Override
  public boolean isCellEditable(EventObject e) {
    return true;
  }

  @Override
  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
//    log.debug("getTableCellEditorComponent["+row+","+column+"]:"+value);
//    this.table = table;
//    this.clickedRow = row;
//    this.clickedCol = column;
    this.cellValue = value;
    return editorComp;
  }

  @Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
//    log.debug("getTableCellRendererComponent["+row+","+column+"]:"+value);
    return this.rendererComp;
  }
}
